﻿using System;

public class Enemy
{
    private int x;
    private int y;
    //each enemy has different image and color
    private char[,] image;
    private ConsoleColor color;

    //this is not used .. i left it so we can make the game more complicated later
    private int life;
    // dummy / coordinator / normal 
    private string type;
    //direction[0] is 1 / 0 / -1 depending on where the enemy will move next direction[1] is the same
    private int[] direction;

    public Enemy(int x, int y, int dirX, int dirY, int hardness, string type = "normal")
    {
        this.X = x;
        this.Y = y;
        this.direction = new int[2] { dirX, dirY };
        this.life = hardness;
        this.type = type;
        this.image = new char[3, 3];
        //gets the image depending on the type of the enemy
        if (this.type == "normal")
        {
            GetNormalImage();
        }
        else if (this.type == "coordinator")
        {
            GetCoordinatorImage();
        }
        else if (this.type == "dummy")
        {
            GetDummyImage();
        }
    }

    //3 types of image
    private void GetDummyImage()
    {
        this.color = ConsoleColor.Yellow;
        this.image[0, 0] = 'O';
        this.image[0, 1] = ' ';
        this.image[0, 2] = 'O';
        this.image[1, 0] = '_';
        this.image[1, 1] = '_';
        this.image[1, 2] = '_';
        this.image[2, 0] = '\\';
        this.image[2, 1] = '_';
        this.image[2, 2] = '/';
    }

    private void GetCoordinatorImage()
    {
        this.color = ConsoleColor.Magenta;
        this.image[0, 0] = 'O';
        this.image[0, 1] = ' ';
        this.image[0, 2] = 'O';
        this.image[1, 0] = ' ';
        this.image[1, 1] = '?';
        this.image[1, 2] = ' ';
        this.image[2, 0] = '-';
        this.image[2, 1] = ' ';
        this.image[2, 2] = '-';
    }

    private void GetNormalImage()
    {
        this.color = ConsoleColor.Cyan;
        this.image[0, 0] = '\\';
        this.image[0, 1] = ' ';
        this.image[0, 2] = '/';
        this.image[1, 0] = 'O';
        this.image[1, 1] = ' ';
        this.image[1, 2] = 'O';
        this.image[2, 0] = '.';
        this.image[2, 1] = '=';
        this.image[2, 2] = '.';
    }

    //helper method to set consoleposition and write a char (for the drawing of the enemy)
    private void Printer(int x, int y, char symb, ConsoleColor color)
    {
        Console.ForegroundColor = color;
        Console.SetCursorPosition(y, x);
        Console.Write(symb);
    }

    //public properties - X Y Direction and Type
    public int X
    {
        get
        {
            return this.x;
        }
        set
        {
            this.x = value;
        }
    }

    public int Y
    {
        get
        {
            return this.y;
        }
        set
        {
            this.y = value;
        }
    }

    public int[] Direction
    {
        get
        {
            return this.direction;
        }
        set
        {
            this.direction = value;
        }
    }

    public int Life
    {
        get
        {
            return this.life;
        }
        set
        {
            this.life = value;
        }
    }

    public string Type
    {
        get
        {
            return this.type;
        }
    }

    //draw
    public void Draw()
    {
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                Printer(this.x + i, this.y + j, this.image[i, j], this.color);
            }
        }
    }

    //just like draw but with " " instead of symbols
    private void ClearEnemyFromConsole(int x, int y)
    {
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                Printer(x + i, y + j, ' ', ConsoleColor.Black);
            }
        }
    }

    //each coordinate is changed according to the direction
    //if you want the enemy to NOT move by diagonal insert logic here
    public void Move()
    {
        ClearEnemyFromConsole(this.x, this.y);
        this.x += direction[0];
        this.y += direction[1];
    }

    //clears the enemy from console and Beeps
    public void Die()
    {
        Console.Beep();
        ClearEnemyFromConsole(this.x, this.y);
    }
}